package yxy.game.pm2.gm.url.mergearea;

import java.util.Collection;

import yxy.apple.logger.Logger;
import yxy.game.pm2.bean.area.AreaBean;
import yxy.game.pm2.bean.module.rank.PlayerRankModule;
import yxy.game.pm2.bean.module.rank.active.ActiveChongBangRankRush;
import yxy.game.pm2.bean.module.rank.active.RankRushEnum;
import yxy.game.pm2.bean.module.rank.openserviceactive.OpenServiceRushRank;
import yxy.game.pm2.bean.module.rank.openserviceactive.OpenServiceRushRankEnum;
import yxy.game.pm2.bean.module.rank.openserviceactive.arenarushrank.OpenServiceArenaRushRank;
import yxy.game.pm2.module.arena.RankArena;
import yxy.game.pm2.module.chibi.RankChibi;
import yxy.game.pm2.module.conquest.RankConquest;
import yxy.game.pm2.module.guard.RankGuard;
import yxy.game.pm2.module.infinite.RankInfinite;
import yxy.game.pm2.module.kow.KowFuture;
import yxy.game.pm2.module.player.RankPlayerLevel;
import yxy.game.pm2.module.player.RankPlayerPower;
import yxy.game.pm2.module.soloride.RankSoloRide;
import yxy.game.pm2.module.tower.RankTower;
import yxy.game.pm2.module.worldboss.RankWorldBoss;
import yxy.game.pm2.module.wuchao.RankWuchao;

public class MergeAreaHandle_排行榜 implements MergeAreaHandle {
	protected static Logger logger = Logger.create(MergeAreaHandle_排行榜.class);

	@Override
	public void handle(AreaBean mainAreaBean, Collection<AreaBean> areas) {
		logger.info("排行榜数据合并开始========================================");
		merge(mainAreaBean, areas, RankPlayerPower.class);// 战力
		merge(mainAreaBean, areas, RankPlayerLevel.class);// 等级

		merge(mainAreaBean, areas, RankConquest.class);// 征战
		merge(mainAreaBean, areas, RankTower.class);// 修炼塔
		merge(mainAreaBean, areas, RankArena.class);// 竞技场

		merge(mainAreaBean, areas, RankChibi.class);// 赤壁之战
		merge(mainAreaBean, areas, RankWorldBoss.class);// 孟获
		merge(mainAreaBean, areas, RankWuchao.class);// 乌巢

		merge(mainAreaBean, areas, RankInfinite.class);// 神将试炼
		merge(mainAreaBean, areas, RankSoloRide.class);// 千里单骑

		merge(mainAreaBean, areas, RankWorldBoss.class);// 世界BOSS
		merge(mainAreaBean, areas, RankGuard.class);// 世界BOSS

		for (AreaBean areaBean : areas) {
			for (Integer type : RankRushEnum.getSequence()) {
				// 冲榜
				ActiveChongBangRankRush mainRank = new ActiveChongBangRankRush(mainAreaBean, type);
				ActiveChongBangRankRush oldRank = new ActiveChongBangRankRush(areaBean, type);
				mainRank.importData(oldRank);
				oldRank.clear(); //被合并的区的排行榜数据，清空
			}
			for (Integer type : OpenServiceRushRankEnum.getSequence()) {
				//开服冲榜
				OpenServiceRushRank openServiceRushRankMain = new OpenServiceArenaRushRank(mainAreaBean.getAreaId(), type);
				OpenServiceRushRank openServiceRushRankOld = new OpenServiceArenaRushRank(areaBean.getAreaId(), type);
				openServiceRushRankMain.importData(openServiceRushRankOld);
				openServiceRushRankOld.clear(); //被合并的区的排行榜数据，清空
			}
		}
		logger.info("排行榜数据合并结束========================================");
	}

	private <T extends PlayerRankModule> void merge(AreaBean mainAreaBean, Collection<AreaBean> areas, Class<T> clazz) {
		try {
			T newRank = (T) clazz.getDeclaredConstructor(AreaBean.class).newInstance(mainAreaBean);
			for (AreaBean areaBean : areas) {
				T rank = (T) clazz.getDeclaredConstructor(AreaBean.class).newInstance(areaBean);
				newRank.importData(rank);

				rank.clear(); //被合并的区的排行榜数据，清空
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println(clazz.getName() + " failed!!!!");
		}
	}

}
